<template>
	<view class="releasePlan-content">
		<view class="release-list">
			<newList :list="[details]" imgField="course_img"
			 titleField="course_title" tipsField="lessson_title" 
			 timeField="time"></newList>
		</view>
		<view class="student-list">
			<view class="student-item" v-for="(item,index) in students" :key="index">
				<view class="student-item_header" @click="clickItem(item)">
					<view class="student-item_header_name">{{item.name}}</view>
					<view class="student-item_header_type">
						<image v-if="item.count!='0'" src="../../../static/imgs/mine/right.png"></image>
						<text v-else class="text_opblack">未提交</text>
					</view>
				</view>
				<l-collapse>
					<l-collapse-item title="查看此同学全部训练计划" :rightIcon="true" @openClick="openClick($event,item)">
						<newList v-if="item.trainings" :list="item.trainings" imgField="course_img"
						 titleField="course_title" tipsField="lessson_title" 
						 timeField="time"></newList>
					</l-collapse-item>
				</l-collapse>
			</view>
		</view>
	</view>
</template>

<script>
	import {getTaskIndex} from "../../../static/js/api/plan.js";
	import {getTrainingStudent} from "../../../static/js/api/training.js"
	import newList from "../../../components/new_list/index.vue";
	import lCollapse from "../../../components/l-collapse/l-collapse.vue"
	import lCollapseItem from "../../../components/l-collapse-item/l-collapse-item.vue"
	export default {
		components: {
			newList,
			lCollapse,
			lCollapseItem
		},
		data() {
			return {
				details: {},
				students: [],
				pickerIndex:0,
			}
		},
		onLoad(option) {
			if (option.trainingId) {
				this.getData(option.trainingId,option.time)
			}
		},
		methods: {
			getData(id,time){
				getTrainingStudent({
					training_id:id
				}).then(res=>{
					console.log(res)
					this.details = res.training
					this.details.time = time
					this.students = res.students
					uni.setNavigationBarTitle({
						title:`${time} 训练计划`
					})
				})
			},
			openClick(type,item){
				console.log(67,type)
				let _this = this
				if(type){
					getTaskIndex({
						student_id: item.student_id,
						page: 1,
						per_page: 9999
					}).then(res=>{
						item.trainings = []
						if (res.trainings) {
							res.trainings.forEach(item => {
								let times = item.create_time.split(" ")
								item.time = times[0]
								item.timeShow = times[0]+' 训练计划'
							})
							item.trainings = res.trainings
							_this.$forceUpdate()
						}
					})
				}
			},
			clickItem(item){
				console.log(item)
				if(item.count!='0'){
					let data = {
						student_id:item.student_id,
						training_id:item.training_id
					}
					uni.navigateTo({
						url:"/pages/releasePlan/correctPlan/evaluate?data="+JSON.stringify(data)
					})
				}else{
					uni.showToast({
						title:"该同学未提交",
						icon:"none",
					})
				}
				
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import url("./index.scss");

	.text_opblack {
		color: $uni-text-color-opblack;
	}

	.text_black {
		color: $uni-text-color-black;
	}

	.text_active {
		color: #FF6E00 !important;
	}
	.release-list{
		background-color: #fff;
	}
	.student-item_header_type{
		image{
			width: 32rpx;
			height: 32rpx;
		}
	}
	
	// .select{
	// 	height:100rpx;
	// 	display: flex;
	// 	width: calc(100% - 30rpx);
	// 	padding-left: 30rpx;
	// 	align-items: center;
	// 	font-size: 14px;
	// 	font-weight: 400;
	// 	color: $uni-text-color-opblack;
	// }
	// .select-input{
	// 	color: #FF6E00;
	// 	margin-left: 20rpx;
	// 	display: flex;
	// 	align-items: center;
	// 	image{
	// 		width: 32rpx;
	// 		height: 32rpx;
	// 	}
	// }
</style>